package com.ittx.dzt.tiktok.service;

import com.ittx.dzt.edi.dto.PlatformApiParamDTO;
import com.ittx.dzt.sys.response.Result;
import com.ittx.dzt.tiktok.constant.TiktokApiConstant;
import com.ittx.dzt.tiktok.handler.AbstractBaseTiktokApiHandler;
import lombok.extern.slf4j.Slf4j;
import open.constant.PlatformApiConstant;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 拆单校验
 * <p>
 * cy.tiktok.order.split.check
 * /fulfillment/202309/orders/split_attributes （拆单校验，非欧美地区拆单发货需先调此接口判断是否允许拆单） https://partner.tiktokshop.com/docv2/page/650aa9210fcef602bf32ae5b?external_id=650aa9210fcef602bf32ae5b
 * </p>
 *
 * @author gywang
 * @since 2024-07-26
 */
@Slf4j
@Service
public class TiktokOrderSplitCheckService extends AbstractBaseTiktokApiHandler<String> {
    @Override
    public String getTiktokMethod() {
        return TiktokApiConstant.ORDER_SPLIT_CHECK;
    }

    @Override
    public String getLocalApiMethod() {
        return PlatformApiConstant.InboundInterface.TIKTOK_ORDER_SPLIT_CHECK;
    }

    @Override
    public Result doProcess(PlatformApiParamDTO platformApiParamDTO, String sourceOrderCodes) {
        Result<?> validResult = checkShopCipherInfo(platformApiParamDTO);
        if (validResult.hasError()) {
            return validResult;
        }
        Map<String, Object> params = new HashMap<>();
        params.put("shop_cipher", getShopCipher(platformApiParamDTO));
        params.put("order_ids", sourceOrderCodes);
        return this.executeTiktokApi(getDefaultUrl(platformApiParamDTO.getStoreConfig()), platformApiParamDTO.getStoreConfig(), params, null, platformApiParamDTO.getRequestId(), TiktokApiConstant.ApiHttpMethod.GET);
    }
}
